package com.demo.datastructure.reorder.insertionSort;

import com.demo.datastructure.reorder.Example;

/**
 * @description: 插入排序
 * @author: ljr
 * @time: 2021/8/31 7:27
 */
public class SimpleInsertSort2 implements Example {

    @Override
    public void sort(Comparable[] a) {
       int length = a.length;
       for(int i = 1; i < length; i++){
           int l = i-1;
           Comparable value = a[i];
           while(less(value, a[l])){
               a[l+1] = a[l];
               if(l-- == 0){
                   break;
               }
           }
           a[++l] = value;
       }
    }
}
